<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="物流编码" prop="logisticsCode">
        <el-input
          v-model="queryParams.logisticsCode"
          placeholder="请输入物流编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="logisticsErrorList" @selection-change="handleSelectionChange">
      <el-table-column type="index" label="序号" width="55" align="center">
        <template slot-scope="scope">
          {{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index +1}}
        </template>
      </el-table-column>
      <el-table-column label="物流编码" align="center" prop="logisticsCode" />
      <el-table-column label="异常信息" align="center" prop="errorMsg" :show-overflow-tooltip="true"/>
      <el-table-column label="负责人" align="center" prop="headStr" />
      <el-table-column label="预计结束时间" align="center" prop="preEndTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.preEndTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理结束时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <el-tag type="primary" v-if="scope.row.status === '0'">待处理</el-tag>
          <el-tag type="primary" v-else>处理完成</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            v-has-permi="['wms:logisticsError:query']"
            v-if="scope.row.status === '0'"
            @click="handleJcError(scope.row)"
          >解除异常</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改物流异常对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form label-width="90px">
        <el-row :gutter="10">
          <el-col :span="12">
            <el-form-item label="预计结束时间">
              {{form.preEndTime}}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="负责人">
              {{form.headStr}}
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="异常信息">
          {{form.errorMsg}}
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-loading="btnLoading">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listLogisticsError, getLogisticsError } from "@/api/wms/logisticsError";
import { handleErrorLogisticsOrder } from "@/api/wms/logisticsOrder";
export default {
  name: "LogisticsError",
  data() {
    return {
      //按钮加载
      btnLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物流异常表格数据
      logisticsErrorList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        logisticsCode: null,
        errorMsg: null,
        headId: null,
        preEndTime: null,
        endTime: null,
        status: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询物流异常列表 */
    getList() {
      this.loading = true;
      listLogisticsError(this.queryParams).then(response => {
        this.logisticsErrorList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        logisticsCode: null,
        errorMsg: null,
        headId: null,
        preEndTime: null,
        createTime: null,
        endTime: null,
        status: null
      };
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 提交按钮 */
    submitForm() {
      this.btnLoading = true
      handleErrorLogisticsOrder(this.formError).then(response => {
        this.$modal.msgSuccess("异常处理成功");
        this.openJcError = false;
        this.getList();
      }).finally(f => {
        this.btnLoading = false
      });
    },
    handleJcError(row){
      this.reset()
      getLogisticsError(row.orderCode).then(res => {
        this.form = res.data
        this.open = true;
      })
    },
  }
};
</script>
